def is_simple(x):
    for d in range(2, int(x**(0.5)+1)):
        if x%d == 0: return False
    return True
def spr():
    spis = []
    for i in range(101,998):
        if is_simple(i) == 1:
            spis.append(i)
        return spis
slovar_digits = {'zero':'0', 'one':'1', 'two':'2', 'three':'3', 'four':'4',\
                 'five':'5', 'six':'6', 'seven':'7', 'eight':'8', 'nine':'9'}
a = input()
sw = a.split()
e = ''
for d in sw:
    e += slovar_digits[d]
if len(e) != 3:
    print('Wrong input')
else:
    a = max(x for x in spr() if x <= int(e))
    b = min(x for x in spr() if x >= int(e))
    if abs(int(e) - a) > abs(int(e) - b):
        print(b)
    else:
        print(a)
